{% extends 'base.html' %}
{% block content %}
<h2>客户列表</h2>
<a href="/customer/create/" class="btn btn-primary">新增客户</a>
<table class="table table-bordered align-middle mb-0">
    <thead class="table-light">
        <tr>
            <th>用户名</th>
            <th>公司名</th>
            <th>手机号</th>
            <th>公司地址</th>
            <th>邮箱</th>
            <th>备注</th>
            <th>价格配置</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        {% for customer in customers %}
        <tr>
            <td>
                {{ customer.username }}
                {% if customer.user %}
                    <br>
                    <a href="/normal_user/edit/{{ customer.user.id }}/" class="link-primary">{{ customer.user.username }}</a>
                {% endif %}
            </td>
            <td>{{ customer.company_name }}</td>
            <td>{{ customer.phone }}</td>
            <td>{{ customer.address }}</td>
            <td>{{ customer.email }}</td>
            <td>{{ customer.remark }}</td>
            <td>
                <a href="/customer/{{ customer.id }}/price_config/" class="btn btn-sm btn-info">价格配置</a>
            </td>
            <td>
                <a href="/customer/edit/{{ customer.id }}/" class="btn btn-sm btn-primary">修改</a>
                <a href="/customer/delete/{{ customer.id }}/" class="btn btn-sm btn-danger" onclick="return confirm('确定要删除该客户吗？');">删除</a>
                {% if not customer.user %}
                    <a href="/customer/generate_user/{{ customer.id }}/" class="btn btn-sm btn-success ms-1">生成普通用户</a>
                {% endif %}
            </td>
        </tr>
        {% empty %}
        <tr><td colspan="8" class="text-center">暂无客户信息</td></tr>
        {% endfor %}
    </tbody>
</table>
{% endblock %}
